/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
var maxDepth = function (root) {
  let maxDepth = 0;

  function findDepth(node, currentDepth) {
    if (node === null) {
      maxDepth = Math.max(currentDepth - 1, maxDepth);
      return;
    } else {
      findDepth(node.left, currentDepth + 1);
      findDepth(node.right, currentDepth + 1);
    }
  }
  findDepth(root, 1);
  return maxDepth;
};